package luoxuan.admin.action;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

import luoxuan.port.dao.PortDao;
import luoxuan.port.entity.Port;
import luoxuan.port.service.PortService;

public class AdminPortAction implements ModelDriven<Port> {

	private Port port=new Port();
	
	private PortService portService;
	
	public void setPortService(PortService portService) {
		this.portService = portService;
	}
	
	@Override
	public Port getModel() {
		return port;
	}
	
	public String addPort(){
		port.setState(1);
		portService.save(port);
		return "success";
	}
	
	public String deletePort(){
		Port existPort=portService.findById(port.getpId());
		if(existPort!=null){
			portService.delete(existPort);
		}
		return "success";
	}
	
	public String updatePort(){
		Port existPort=portService.findById(port.getpId());
		if(existPort!=null){
			if(existPort.getState()==0){
				existPort.setState(1);
			}else if(existPort.getState()==1){
				existPort.setState(0);
			}
			portService.update(existPort);
		}
		return "success";
	}
	
	public String findAll(){
		List<Port> list=portService.findAll();
		ActionContext.getContext().getValueStack().set("list", list);
		return "findAll";
	}

}
